import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_dk_form/flutter_dk_form.dart';
import 'package:dk_flutter_base/dk_ui.dart';
import 'page_time_axis_demo.dart';

class WidgetsDemoPage extends StatefulWidget {
  static const String routeName = '/page/widgets_demo_page';
  static const String name = "Widgets Demo";

  @override
  _WidgetsDemoState createState() => _WidgetsDemoState();
}

class _WidgetsDemoState extends State<WidgetsDemoPage> {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Widgets Demo',
      home: Scaffold(
        appBar: AppBar(
          title: Text('Widgets Demo'),
        ),
        body: SingleChildScrollView(
          child: Column(
            children: <Widget>[
              Text('多行输入框'),
              _InputWidget(),
              Text('带标题的多行输入框'),
              _MultipleRemarkWidget(),
              Text('带标题的多行输入框_不需要controller'),
              _MultipleInputWidget(),
              Text('带标题的多行输入框_不需要controller_标题下划线右侧边距屏幕0'),
              _MultipleInputMarginRight0Widget(),
              Text('pull down'),
              _PullDownWidget(),
              Text('DropDownWidget'),
              _DropDownWidget(),
              Text('单行输入'),
              _SingleInput(),
              Text('开关'),
              _SwitchWidget(),
              Text("数字输入框"),
              _NumInputWidget(),
            ],
          ),
        ),
      ),
    );
  }
}

class _InputWidget extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    TextEditingController controller = TextEditingController();
    return InputWidget(
      placeholder: '测试',
      maxLength: 100,
      showWaringText: true,
      returnKeyDownKeyBoard: true,
      controller: controller,
    );
  }
}

class _MultipleRemarkWidget extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    TextEditingController controller = TextEditingController();
    return MultipleRemarkWidget(
      title: '我是标题',
      placeholder: '测试',
      maxLength: 100,
      showWaringText: true,
      returnKeyDownKeyBoard: true,
      controller: controller,
    );
  }
}

class _MultipleInputWidget extends StatelessWidget {
  void onChangedHandler(String value) {
    print('_MultipleInputWidget $value');
  }

  @override
  Widget build(BuildContext context) {
    return MultipleInputWidget(
      title: '我是标题',
      placeholder: '测试',
      initialValue: 'abc',
      onChanged: onChangedHandler,
    );
  }
}

class _MultipleInputMarginRight0Widget extends StatelessWidget {
  void onChangedHandler(String value) {
    print('_MultipleInputMarginRight0Widget $value');
  }

  @override
  Widget build(BuildContext context) {
    return MultipleInputWidget(
      title: '我是标题',
      placeholder: '测试',
      initialValue: 'abc',
      onChanged: onChangedHandler,
      hasLine: false,
      titleTextStyle: TitleTextStyle.TitleSmall,
    );
  }
}

class _PullDownWidget extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return PulldownSelectItemWidget(
      title: 'test',
      placeholder: 'haha',
      isLine: true,
      content: 'lala',
      allowEmpty: false,
      tapCallback: () {
        DkPicker picker = DkPicker(
          title: Text('标题', style: TextStyle(fontSize: 14, color: Color(0xFF999999)),),
            adapter: PickerDataAdapter<String>(pickerdata: ['aa', 'bb']),
            onSelect: (DkPicker picker, int index, List<int> selecteds) {
              print('index = $index  selecteds=$selecteds');
            },
            onConfirm: (DkPicker picker, List<int> selecteds) {
              print('onConfirm selecteds=$selecteds');
            });
        picker.showModal(context);
      },
    );
  }
}

class _SingleInput extends StatelessWidget {
  final TextEditingController controller = TextEditingController();
  @override
  Widget build(BuildContext context) {
    return SingleInputItemWidget(
      title: '我是标题',
      placeholder: '测试',
      controller: controller,
    );
  }
}

class _SwitchWidget extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return SwitchChoiceItemWidget(
      title: '打开',
      isLine: true,
      open: true,
      leftText: '是',
      rightText: '否',
    );
  }
}

class _DropDownWidget extends StatelessWidget {
  final List<DkDropDownItem> list = [
    DkDropDownItem(1, 'aa'),
    DkDropDownItem(2, 'bb')
  ];

  @override
  Widget build(BuildContext context) {
    return DropDownWidget(
      title: '原因',
      hasLine: true,
      placeHolder: 'lala',
      //list: list,
      onChanged: (value) {
        print(
            'DropDownWidget select value= ${value.value} title= ${value.title}');
      },
    );
  }
}

class _NumInputWidget extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return NumInputWidget();
  }
}
